package edu.dlust.trading_platform.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import edu.dlust.trading_platform.DataBean.CommentBean;
import edu.dlust.trading_platform.R;

public class CommentAdapter extends BaseAdapter {
    private List<CommentBean> list;
    private LayoutInflater layoutInflater;

    public CommentAdapter(Context context, List<CommentBean> list) {
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list==null ? 0: list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View converView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(converView == null){
            converView = layoutInflater.inflate(R.layout.item_comment_layout,null);
            viewHolder = new ViewHolder(converView);
            converView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) converView.getTag();
        }
        CommentBean commentBean = (CommentBean) getItem(position);
        viewHolder.Name.setText(commentBean.getUName());
        viewHolder.content.setText(commentBean.getMessage());
        viewHolder.time.setText(commentBean.getTime());
        viewHolder.image.setBackgroundResource(R.drawable.user);
        return converView;
    }
    class ViewHolder{
        TextView Name,content,time;
        ImageView image;
        public ViewHolder(View view){
            Name = (TextView) view.findViewById(R.id.tv_comment_nickname);
            content = (TextView) view.findViewById(R.id.tv_comment_content);
            time = (TextView) view.findViewById(R.id.tv_comment_time);
            image = (ImageView) view.findViewById(R.id.iv_comment_avatar);
        }
    }
}
